import { defineStore } from "pinia";

const keepAliveStore = defineStore('keepAlive',{
  state:() => {
    return {
      keepAliveComponentsName:[]
    }
  },
  getters:{
    getKeepAliveComponentsName() {
      return this.keepAliveComponentsName
    }
  },
  actions:{
    // 重置，Push, splice keep-alive对象
    setKeepAliveComponentsName(nameArr) {
      this.keepAliveComponentsName = nameArr
    },
    addKeepAliveComponentsName(name) {
      this.keepAliveComponentsName.push(name)
    },
    delKeepAliveComponentsName(name) {
      const key = this.keepAliveComponentsName.indexOf(name)
      if (key !== -1) {
        this.keepAliveComponentsName.splice(key, 1)
        console.log(this.keepAliveComponentsName)
      }
    }
  }
})


export default keepAliveStore;